#include <iostream>
#include <string>
using namespace std;

size_t FindFirstRight(const string& str, size_t pos=0) {
	size_t left=0;
	for (size_t b=str.find_first_of("()",pos); b!=string::npos;
				b=str.find_first_of("()",b+1)	
					){
			if (b!=string::npos) {
			if (str[b]=='(')
				left+=1;
			else {
				if (left==0) 
						return b;
				else left-=1;
			}
			}
			//else throw("found non paired parenthese!");
			else return b;
	}
}

int main () {
		cout << "Input the string, and I will found the outest parenthese of it:\n";
		 string str;
		 cin >> str;
		 cout << "You inputed "<< str <<endl;
		size_t l=str.find_first_of("()");
		if (l==string::npos) 
				cout << "no parenthese!\n";
		else if (str[l]==')')
				cout << "wrong parenthese!\n";
		else {size_t r=FindFirstRight(str,l+1);
			if (r==string::npos) 
				cout << "wrong parenthese!\n";
			else
				cout << string(str,l,r-l+1)<<endl;
		}
		return 0;
}
